<template>
	<view>
		<view class="item " v-for="(item,index) in productList" :key="index">
			<image :src="item.productIcon" mode="aspectFit"></image>
			<view class="item_r">
				<view class="item_flex">
					<view class="title">{{item.productName}}</view>
					<view class="price1">
						<text>￥</text>{{Prices(item)}}
					</view>
				</view>
				<view class="item_flex">
					<view class="price2">
						<text>￥</text>{{item.productPrice}}<text class="t2">/{{item.productUnit}}</text>
					</view>
					<view class="price2">
						x{{item.productCount}}
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 166rpx;">

		</view>
		<view class="btn_bottom">
			<view class="btn_left ">
				共{{productList.length}}种，商品{{allCount}}件，合计:<text class="t1">￥</text> <text class="t2">{{allPrice}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import {
		reactive,
		ref,
		computed
	} from 'vue';
	const productList = ref([])
	const Prices = computed(() => {
		return (item)=>{
			return item.productPrice * item.productCount
		}
	})
	const allPrice = computed(() => {
		let price = 0;
		productList.value.forEach(its => {
			price += its.productPrice * its.productCount
		})
		return price.toFixed(2)
	})
	const allCount = computed(() => {
		let total = 0;
	productList.value.forEach(its => {
			total += its.productCount
		})
		return total
	})
	onLoad(() => {
		productList.value = uni.getStorageSync('Infolist')
		
	})
</script>

<style lang="scss">
	page {
		background: #F8F8F8;
	}

	.item {
		width: 710rpx;
		background: #FFFFFF;
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		margin: 20rpx auto;
		border-radius: 20rpx;

		image {
			width: 120rpx;
			height: 120rpx;
			border-radius: 20rpx;
			border: 1px solid #efefef;
		}

		.item_r {
			flex: 1;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			height: 120rpx;

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #000000;
			}

			.price1 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				font-size: 32rpx;
				color: #000000;

				text {
					font-size: 24rpx;
				}
			}

			.price2 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #979797;
			}

			.item_flex {
				flex: 1;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}

	}

	.item:last-child {
		border: none;
	}

	.btn_bottom {
		width: 100%;
		height: 100rpx;
		z-index: 9;
		bottom: 0%;
		position: fixed;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		line-height: 100rpx;
		background: #fff;

		.btn_left {
			text-align: right;
			margin-right: 30rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #000000;

			.t1 {
				color: #FF0000;
			}

			.t2 {
				font-size: 40rpx;
				color: #FF0000;
			}
		}
	}
</style>